package com.whmskj.xjlhsc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.whmskj.xjlhbc.db.DataSource;
import com.whmskj.xjlhbc.db.DataSourceType;
import com.whmskj.xjlhsc.controller.vo.JtjcVo;
import com.whmskj.xjlhsc.entity.Sb02EquipmentCounterAccount;
import com.whmskj.xjlhsc.entity.WbRecord;
import com.whmskj.xjlhsc.mobie.equipmentManage.entity.vo.JtListVo;
import com.whmskj.xjlhsc.mobie.equipmentManage.entity.vo.MachineVO;
import com.whmskj.xjlhsc.mobie.equipmentManage.entity.vo.ProductionCapacityVo;
import com.whmskj.xjlhsc.mobie.equipmentManage.entity.vo.XSJRealTimeInfoVO;
import com.whmskj.xjlhsc.view.entity.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

@Mapper
public interface Sb02EquipmentCounterAccountMapper extends BaseMapper<Sb02EquipmentCounterAccount> {

    @Select("select '梳棉' name,yx,total,round(yx/total * 100,2) kjl,xl,total-yx lt,0 jhtc,0 wb,0 lx from (select count(1) total,sum(if(devicestate='正常运行',1,0))yx,0 xl from xjsc.smj_realtime) a")
    JtjcVo selectSmJtjc();

    @Select("select '并条' name,yx,total,round(yx/total * 100,2) kjl,xl,total-yx lt,0 jhtc,0 wb,0 lx from (select count(1) total,count(1)yx,0 xl from xjsc.btj_realtime) a")
    JtjcVo selectBtJtjc();

    @Select("select '粗纱' name,yx,total,round(yx/total * 100,2) kjl,xl,total-yx lt,0 jhtc,0 wb,0 lx from (select count(1) total,sum(if(devicestate='正常运行',1,0))yx,0 xl from xjsc.csj_realtime) a")
    JtjcVo selectCsJtjc();

    @Select("select '细纱' name,yx,total,round(yx/total * 100,2) kjl,xl,total-yx lt,0 jhtc,0 wb,0 lx from (select count(1) total,sum(if(devicestate='正常运行',1,0))yx,0 xl from xjsc.xsj_realtime) a")
    JtjcVo selectXsJtjc();
    @Select("select '络筒' name,yx,total,round(yx/total * 100,2) kjl,xl,total-yx lt,0 jhtc,0 wb,0 lx from (select count(1) total,count(1) yx,round(avg(r23005),2) xl from xjsc.ltj_realtime) a")
    JtjcVo selectLtJtjc();

    List<StateVo> selectJtState(String process);

    List<JtListVo> selectJtNumber(@Param(value = "process") String process, @Param(value = "state") String state, @Param(value ="keyWord") String keyWord);

    @Select("select id as mesId,platform from sb02EquipmentCounterAccount where devicename = #{deviceName}")
    List<MachineVO> getMachineVOList(String deviceName);
    /**
     *实时数据
     * @param id
     * @param shift
     * @return
     */
    @DataSource(DataSourceType.MASTER)
    XSJRealTimeInfoVO selectRealTimeInfoVo(@Param(value = "id") Integer id, @Param(value = "shift") String shift);

    /**
     * 产能信息
     * @param id
     * @return
     */
    List<ProductionCapacityVo> selectProductionCapacityVo(@Param(value = "id") Integer id);

    /**
     * 获取机台分组
     * @param process
     * @return
     */
    List<Sb02EquipmentCounterAccount> machineGroup(String process);

    @Select("select concat(equipment,'-',typeOfSpecification) from deviceSpecificationModel\n" +
            "where equipment='细纱机'")
    String getDeviceTypeName(String deviceName);

    /**
     * 获取同名其他机台的信息
     * @param mesId
     * @return
     */
    List<ProductionCapacityVo> selectDeviceCompareInfo(Integer mesId);
    @DataSource(DataSourceType.MASTER)
    List<Double> selectDeviceXl(@Param(value = "collect") List<Integer> collect);

    List<StateVo> getDevicesState(String process);

    List<DeviceRunEfficiencyVo> selectDeviceRunEfficiency(@Param(value = "dateType") Integer dateType,
                                                          @Param(value = "startTime") String startTime,
                                                          @Param(value = "endTime") String endTime);

    List<ClassesRunEfficiencyVo> selectClassesRunEfficiency(@Param(value = "startTime") String startTime,
                                                            @Param(value = "endTime") String endTime);

    List<RecentlyEnergyVo> selectRecentlyEnergy(@Param(value = "deviceId") Integer deviceId,
                                                @Param(value = "endTime") LocalDate startTime,
                                                @Param(value = "startTime") LocalDate endTime);

    Integer selectMaintenance(@Param(value = "deviceId") Integer deviceId,
                                     @Param(value = "startTime") String startTime,
                                     @Param(value = "endTime") String endTime,
                                     @Param(value = "status") Integer... status);

    Sb02EquipmentCounterAccount selectSb02EquipmentCounterAccountById(Integer mesId);

    List<Map<String, Object>> selectDeviceSuspension(@Param(value = "workshop") Integer workshop);

    List<Map<String, Object>> selectTemperature(Integer workshop);

    List<DBJYiledVo> selectDBJYield(@Param(value = "mesId") Integer mesId,
                                    @Param(value = "startTime") String startTime,
                                    @Param(value = "endTime") String endTime);

    LinkedHashMap<String, Object> selectYXJYield(Integer mesId);

    List<StateVo> selectIndexState();
}
